package FIT::Util::Constraint;

use FIT::Class;
use Declare::Constraints::Simple -Library;
use base 'Declare::Constraints::Simple::Library';

# create a DCS constraint from a Moose type
# use:
#    $profile = MooseType 'Num';

constraint 'MooseType' => sub {
    my $moose_name = shift;
    my $moose_constraint =
        Moose::Util::TypeConstraints::find_type_constraint($moose_name) ||
        die "No Moose constraint called [$moose_name] found";

    return sub {
        my $message = $moose_constraint->validate(shift);
        return _true unless defined $message;
        return _false($message);
    };
};

